home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWExtMgr.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.4 KB  |  164 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWExtMgr.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWEXTMGR_H
  13. #include "FWExtMgr.h"
  14. #endif
  15.  
  16. // ----- OpenDoc Includes -----
  17.  
  18. #ifndef _ISOSTR_
  19. #include "ISOStr.h"
  20. #endif
  21.  
  22. #ifndef SOM_ODExtension_xh
  23. #include "Extensn.xh"
  24. #endif
  25.  
  26. #if FW_LIB_EXPORT_PRAGMAS
  27. #pragma lib_export on
  28. #endif
  29.  
  30. #ifdef FW_BUILD_MAC
  31. #pragma segment extensionmanager
  32. #endif
  33.  
  34. //========================================================================================
  35. //    class FW_CPrivExtensionMap
  36. //========================================================================================
  37.  
  38. //----------------------------------------------------------------------------------------
  39. //    FW_CPrivExtensionMap::FW_CPrivExtensionMap
  40. //----------------------------------------------------------------------------------------
  41.  
  42. FW_CPrivExtensionMap::FW_CPrivExtensionMap()
  43. {
  44. }
  45.  
  46. //----------------------------------------------------------------------------------------
  47. //    FW_CPrivExtensionMap::~FW_CPrivExtensionMap
  48. //----------------------------------------------------------------------------------------
  49.  
  50. FW_CPrivExtensionMap::~FW_CPrivExtensionMap()
  51. {
  52. }
  53.  
  54. //----------------------------------------------------------------------------------------
  55. //    FW_CPrivExtensionMap::KeysMatch
  56. //----------------------------------------------------------------------------------------
  57.  
  58. FW_Boolean FW_CPrivExtensionMap::KeysMatch(FW_PrivKeyType key1,FW_PrivKeyType key2) const
  59. {
  60.     return !ODISOStrCompare((ODISOStr) key1, (ODISOStr) key2);
  61. }
  62.  
  63. //========================================================================================
  64. //    class FW_CExtensionManager
  65. //========================================================================================
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //    FW_CExtensionManager::~FW_CExtensionManager
  69. //----------------------------------------------------------------------------------------
  70.  
  71. FW_CExtensionManager::~FW_CExtensionManager()
  72. {
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_CExtensionManager::FW_CExtensionManager
  77. //----------------------------------------------------------------------------------------
  78.  
  79. FW_CExtensionManager::FW_CExtensionManager(FW_CPart* part)
  80.     : fPart(part),
  81.     fNameToCreateFuncMap(),
  82.     fActiveExtensions()
  83. {
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    FW_CExtensionManager::HasExtension
  88. //----------------------------------------------------------------------------------------
  89.  
  90. FW_Boolean FW_CExtensionManager::HasExtension(Environment *ev, const char* const name)
  91. {
  92.     return fNameToCreateFuncMap.ContainsKey((FW_PrivKeyType)name);
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    FW_CExtensionManager::RegisterExtension
  97. //----------------------------------------------------------------------------------------
  98.  
  99. void FW_CExtensionManager::RegisterExtension(Environment *ev, const char * const name, CreateExtensionFunc func)
  100. {
  101.     FW_ASSERT(!fNameToCreateFuncMap.ContainsKey((FW_PrivKeyType)name));
  102.     fNameToCreateFuncMap.AddPair((FW_PrivKeyType)name, (FW_PrivValueType)func);
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. //    FW_CExtensionManager::AcquireExtension
  107. //----------------------------------------------------------------------------------------
  108.  
  109. ODExtension* FW_CExtensionManager::AcquireExtension(Environment *ev, const char* const name)
  110. {
  111.     ODExtension *theExtension = (ODExtension *) fActiveExtensions.ValueAtKey((FW_PrivKeyType)name);
  112.     if (!theExtension)
  113.     {
  114.         CreateExtensionFunc func = (CreateExtensionFunc) fNameToCreateFuncMap.ValueAtKey((FW_PrivKeyType)name);
  115.         if (func)
  116.         {
  117.             theExtension = (func)(ev, fPart, name);
  118.             if (theExtension)
  119.                 fActiveExtensions.AddPair((FW_PrivKeyType)name, (FW_PrivValueType)theExtension);
  120.         }
  121.     }
  122.     if (theExtension)
  123.         theExtension->Acquire(ev);
  124.     return theExtension;
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    FindValueInMap
  129. //----------------------------------------------------------------------------------------
  130.  
  131. static FW_PrivKeyType FindValueInMap(FW_CPrivDictionaryList* list, FW_PrivValueType value)
  132. {
  133.     FW_PrivKeyType result = 0;
  134.     FW_CPrivLinkedListIterator *iter = list->CreateIterator();
  135.     FW_CPrivLink *link;
  136.     for (link=iter->First(); iter->IsNotComplete(); link=iter->Next())
  137.     {
  138.         FW_CPrivAssociation *assoc = (FW_CPrivAssociation*) link;
  139.         if (assoc->GetValue() == value)
  140.         {
  141.             result = assoc->GetKey();
  142.             break;
  143.         }
  144.     }
  145.     return result;
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. //    FW_CExtensionManager::ReleaseExtension
  150. //----------------------------------------------------------------------------------------
  151.  
  152. void FW_CExtensionManager::ReleaseExtension(Environment *ev, ODExtension *extension)
  153. {
  154.     FW_ASSERT(extension!=NULL);
  155.     FW_ASSERT(extension->GetRefCount(ev) == 0);
  156.  
  157.     // We only need to remove the extenson from the map when it's about to be destroyed
  158.     FW_PrivKeyType name = FindValueInMap(&fActiveExtensions, extension);
  159.     if (name)
  160.         fActiveExtensions.RemoveKey(name);
  161.  
  162. }
  163.  
  164.